<template>
    <Modal
        :title="modalTitle"
        v-model="modalOpen"
        :width="500"
        @on-cancel="cancel"
    >
        <div class="addUserToExempt">
            <!-- 全部模糊查询 -->
            <Form ref="formData" :model="formData" :label-width="80" :rules="formRules">
                <Row>
                    <Col span="16">
                        <FormItem label="用户" prop="username">
                            <Select v-model="formData.username" clearable placeholder="请选择" filterable class="s1" :disabled="!formData.edit">
                                <Option v-for="(item,k1) in userData" :value="item.username"  :label="item.userRealName"
                                        :key="k1" ></Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="16">
                        <FormItem label="单笔合同最高限额" prop="limitAmt" >
                            <RuiNumber clearable :precision="2" v-model="formData.limitAmt"  :max="1000000000" type="currency"   placeholder class="input"/>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="12">
                        <FormItem label="费用类型" prop="costType">
                            <Select v-model="formData.costType" clearable placeholder="请选择" :disabled="!formData.edit"
                                    class="input" filterable>
                                <Option v-for="(item,index) in dataDict.exemptFeeTypeDict" :value="item.value"
                                        :key="index">{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <row>
                    <Col span="150">
                        <div>
                            <Button type="primary" size="small" @click="handleSubmit('formData')"
                                    style="margin-left: 150px">保存
                            </Button>
                        </div>
                    </Col>
                </row>
            </Form>
        </div>
        <div slot="footer"></div>
    </Modal>
</template>

<script>
    import {
        save,
        getUserOne
    } from "@/projects/basic/api/contract/fee-waiver/exempt-configuration/index";

    export default {
        // 已激活案件列表 弹窗
        name: "addUserToExempt",
        components: {},
        props: {
            isModalOpen: {
                type: Boolean,
                required: true
            },
            baseData: {
                type: Object,
                required: true
            },
            dataDict: {
                type: Object,
                required: true
            },
            closeModal: {},
            userData: {
                type: Array,
                required: true
            },
            modalTitle: {
                type: String,
                default: "已激活案件列表"
            },

        },
        data() {
            return {
                loading: false,
                modalOpen: this.isModalOpen,
                formData: {
                    limitAmt: null,
                    username: "",
                },
                formRules: {
                    username: [
                        {required: true, message: "请选择一项", trigger: "blur"}
                    ],
                    limitAmt: [
                        {required: true, message: "请输入"}
                    ]
                },

            };
        },
        watch: {
            isModalOpen: function (newVal) {
                this.modalOpen = newVal
                if (newVal) {
                    this.$refs.formData.resetFields();
                    this.formData = Object.assign({},this.formData,this.baseData)
                    // this.isModalOpen = newVal;
                    this.loading = true;
                }
            }
        },
        created() {

        },
        mounted() {
            this.init();


        },
        methods: {
            init() {

            },
            cancel() {
                this.$emit("closeModal")

            },
            getUserOne() {
                this.formData.username = this.formData.user
                console.log("this.formData.username", this.formData.user)
                getUserOne(this.formData.user).then(res => {
                    if (res.code === "0000") {
                        this.formData.username = res.data.username
                    }
                    this.$emit("closeModal")
                })
            },
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        save(this.formData).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success("操作成功");
                            }
                            this.$emit("closeModal")
                        }).catch(() => {

                        });
                    } else {
                        this.$Message.error('Fail!');
                    }
                })

            },


        }
    };
</script>
<style scoped lang="less">
    .vertical-center-modal {
        display: flex;
        align-items: center;
        justify-content: center;

        .ivu-modal {
            top: 0;
        }
    }
    .input{
        width: 240px;
    }
    .ActivatedCase {
        .new-apply-table {
            padding-top: 18px;
        }

        .table-page {
            padding-top: 16px;
        }
    }

    .text-center {
        text-align: center;
    }
</style>
